package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.entity.ExamStore;
import com.example.mapper.*;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import javax.naming.ldap.HasControls;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * @Description:
 * @Author: aimi
 * @Create: 2024-06-08
 **/
@Service
public class SystemServiceImpl {
    @Resource
    private SpuMapper spuMapper;
    @Resource
    private UserMapper userMapper;
    @Resource
    private OrderMapper orderMapper;
    @Resource
    private StoreMapper storeMapper;
    @Resource
    private ExamStoreMapper examStoreMapper;
    @Resource
    private FlowServiceImpl flowService;


    public Map<String, Map<String, Object>> getAdminDashMap() {
        //基本信息
        HashMap<String, Object> basicMap = new HashMap<>();
        basicMap.put("goodsNum",spuMapper.selectCount(null));
        basicMap.put("memberNum",userMapper.selectCount(null));
        basicMap.put("orderNum",orderMapper.selectCount(null));
        basicMap.put("storeNum",storeMapper.selectCount(null));
        //今日待办
        HashMap<String, Object> waitMap = new HashMap<>();
        waitMap.put("waitGoodsNum",spuMapper.getExamSpuList().size());
        waitMap.put("waitStoreNum",examStoreMapper.selectCount(new QueryWrapper<ExamStore>().eq("status",0)));
        waitMap.put("waitComplainNum",new Random().nextInt(8));
        //流量概括
        Map<String, Object> flowMap = flowService.getAdminFlowMap();

        HashMap<String, Map<String, Object>> dashMap = new HashMap<>();
        dashMap.put("basic",basicMap);
        dashMap.put("wait",waitMap);
        dashMap.put("flow",flowMap);
        return dashMap;
    }
}